home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / WINSYS.PAK / SYSTEM.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  305 lines

  1. //----------------------------------------------------------------------------
  2. // Borland WinSys Library
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   5.10  $
  6. //
  7. // Definition of TSystem, a system information provider class
  8. //----------------------------------------------------------------------------
  9. #if !defined(WINSYS_SYSTEM_H)
  10. #define WINSYS_SYSTEM_H
  11.  
  12. #if !defined(WINSYS_DEFS_H)
  13. # include <winsys/defs.h>
  14. #endif
  15. #if !defined(WINSYS_WSYSINC_H)
  16. # include <winsys/wsysinc.h>
  17. #endif
  18.  
  19. //
  20. // Define Win95 platform constant if not defined in system headers
  21. //
  22. #if !defined(VER_PLATFORM_WIN32_WINDOWS)
  23. # define VER_PLATFORM_WIN32_WINDOWS 1
  24. #endif
  25.  
  26. #if defined(BI_NAMESPACE)
  27. namespace ClassLib {
  28. #endif
  29.  
  30. //
  31. // class TSystem
  32. // ~~~~~ ~~~~~~~
  33. class _WSYSCLASS TSystem {
  34.   public:
  35.  
  36.     // High level capability support queries
  37.     //
  38.     static bool SupportsExceptions();
  39.     static bool SupportsThreads();
  40.     static bool SupportsInstanceData();
  41.  
  42.     static bool Has3dUI();
  43.     static bool HasSmallCaption();
  44.     static bool HasSmallIcon();
  45.  
  46.     // More specific platform type queries
  47.     //
  48. #if defined(BI_PLAT_WIN16)
  49.     static bool IsWoW();
  50.     static bool IsWin95();
  51. #endif
  52. #if defined(BI_PLAT_WIN32)
  53.     static bool IsNT();
  54.     static bool IsWin95();
  55.     static bool IsWin32s();
  56. #endif
  57.  
  58.     enum TPlatformId {
  59. #if defined(BI_PLAT_WIN32)
  60.       Win32s       = VER_PLATFORM_WIN32s,
  61.       Win32Windows = VER_PLATFORM_WIN32_WINDOWS,
  62.       Win32NT      = VER_PLATFORM_WIN32_NT,
  63.       Win16        = -1,
  64. #else
  65.       Win32s       = -1,
  66.       Win32Windows = -1,
  67.       Win32NT      = -1,
  68.       Win16        = 0,
  69. #endif
  70.     };
  71.     static uint GetPlatformId();
  72.  
  73.     // Version information
  74.     //
  75.     static uint GetVersion();
  76.     static uint GetVersionFlags();
  77.  
  78.     static uint GetMajorVersion();
  79.     static uint GetMinorVersion();
  80.     static uint GetBuildNumber();
  81.  
  82.     static const _TCHAR* GetVersionStr();
  83.  
  84.     // Hardware information
  85.     //
  86.     enum TProcessor {
  87. #if defined(BI_PLAT_WIN32)
  88.       Intel386     = PROCESSOR_INTEL_386,
  89.       Intel486     = PROCESSOR_INTEL_486,
  90.       IntelPentium = PROCESSOR_INTEL_PENTIUM,
  91.       MipsR4000    = PROCESSOR_MIPS_R4000,
  92.       Alpha21064   = PROCESSOR_ALPHA_21064,
  93. #else
  94.       Intel386,
  95.       Intel486,
  96.       IntelPentium,
  97.       MipsR4000    = -1,
  98.       Alpha21064   = -1,
  99. #endif
  100.       Ppc601       = -1,
  101.       Ppc603       = -1,
  102.       Ppc604       = -1,
  103.       Ppc620       = -1,
  104.     };
  105.     static TProcessor GetProcessorType();
  106.  
  107.   protected:
  108.  
  109. #if defined(BI_PLAT_WIN32)
  110.     // Class that encapsulates the OSVERSIONINFO struct and the GetVersionEx()
  111.     // Win32 call.
  112.     //
  113.     class TVersionInfo : private _OSVERSIONINFOA {
  114.       public:
  115.         TVersionInfo();
  116.         uint GetMajorVersion() const;
  117.         uint GetMinorVersion() const;
  118.         uint GetBuildNumber() const;
  119.         uint GetPlatformId() const;
  120.         const _TCHAR* GetVersionStr() const;
  121.     };
  122.  
  123.     // Return an initialized version info object
  124.     //
  125.     static TVersionInfo& GetVerInfo();
  126.  
  127.     // Class that encapsulates the _SYSTEM_INFO struct and the GetSystemInfo()
  128.     // Win32 call.
  129.     //
  130.     class TSystemInfo : private _SYSTEM_INFO {
  131.       public:
  132.         TSystemInfo();
  133.         TProcessor GetProcessorType() const;
  134.     };
  135.  
  136.     // Return an initialized system info object
  137.     //
  138.     static TSystemInfo& GetSystemInfo();
  139. #endif
  140. };
  141.  
  142. #if defined(BI_NAMESPACE)
  143. }     // namespace ClassLib
  144. #endif
  145.  
  146. //----------------------------------------------------------------------------
  147. // Inlines
  148. //
  149.  
  150. //
  151. // Does this OS support tiny caption (via the WS_EX_TOOLWINDOW style)
  152. //
  153. inline bool TSystem::HasSmallCaption()
  154. {
  155.   return Has3dUI();
  156. }
  157.  
  158. //
  159. // Does this OS support small window icons
  160. //
  161. inline bool TSystem::HasSmallIcon()
  162. {
  163.   return Has3dUI();
  164. }
  165.  
  166.  
  167. #if defined(BI_PLAT_WIN16)
  168.  
  169. //
  170. // Return true if the system has exception suport built in and the runtime
  171. // library uses it for stack unwinding support.
  172. //
  173. inline bool TSystem::SupportsExceptions() {
  174.   return false;
  175. }
  176.  
  177. //
  178. // Return true if the system has thread suport built in and the runtime
  179. // library uses it.
  180. //
  181. inline bool TSystem::SupportsThreads() {
  182.   return false;
  183. }
  184.  
  185. //
  186. // Return true if the system has suport for per-instance data built in and the
  187. // runtime library uses it.
  188. //
  189. inline bool TSystem::SupportsInstanceData() {
  190.   return false;
  191. }
  192.  
  193. //
  194. inline uint TSystem::GetPlatformId() {
  195.   return Win16;
  196. }
  197.  
  198. //
  199. inline uint TSystem::GetMajorVersion() {
  200.   return LOBYTE(LOWORD(GetVersion()));
  201. }
  202.  
  203. //
  204. inline uint TSystem::GetMinorVersion() {
  205.   return HIBYTE(LOWORD(GetVersion()));
  206. }
  207.  
  208. //
  209. inline const _TCHAR* TSystem::GetVersionStr() {
  210.   return "";
  211. }
  212.  
  213. #elif defined(BI_PLAT_WIN32)
  214.  
  215. //
  216. inline bool TSystem::IsNT() {
  217.   return GetPlatformId() == Win32NT;
  218. }
  219.  
  220. //
  221. inline bool TSystem::IsWin95() {
  222.   return GetPlatformId() == Win32Windows;
  223. }
  224.  
  225. //
  226. inline bool TSystem::IsWin32s() {
  227.   return GetPlatformId() == Win32s;
  228. }
  229.  
  230. //
  231. inline uint TSystem::GetPlatformId() {
  232.   return GetVerInfo().GetPlatformId();
  233. }
  234.  
  235. //
  236. inline TSystem::TProcessor TSystem::GetProcessorType() {
  237.   return GetSystemInfo().GetProcessorType();
  238. }
  239.  
  240. //
  241. inline uint TSystem::GetMajorVersion() {
  242.   return GetVerInfo().GetMajorVersion();
  243. }
  244.  
  245. //
  246. inline uint TSystem::GetMinorVersion() {
  247.   return GetVerInfo().GetMinorVersion();
  248. }
  249.  
  250. //
  251. inline uint TSystem::GetBuildNumber() {
  252.   return GetVerInfo().GetBuildNumber();
  253. }
  254.  
  255. //
  256. inline const _TCHAR* TSystem::GetVersionStr() {
  257.   return GetVerInfo().GetVersionStr();
  258. }
  259.  
  260. //
  261. inline TSystem::TSystemInfo::TSystemInfo() {
  262.   // no struct size to fill in...
  263.   ::GetSystemInfo(this);
  264. }
  265.  
  266. //
  267. inline TSystem::TProcessor TSystem::TSystemInfo::GetProcessorType() const {
  268.   return (TProcessor)dwProcessorType;
  269. }
  270.  
  271. //
  272. inline TSystem::TVersionInfo::TVersionInfo() {
  273.   dwOSVersionInfoSize = sizeof *this;
  274.   ::GetVersionEx(this);
  275. }
  276.  
  277. //
  278. inline uint TSystem::TVersionInfo::GetMajorVersion() const {
  279.   return dwMajorVersion;
  280. }
  281.  
  282. //
  283. inline uint TSystem::TVersionInfo::GetMinorVersion() const {
  284.   return dwMinorVersion;
  285. }
  286.  
  287. //
  288. inline uint TSystem::TVersionInfo::GetBuildNumber() const {
  289.   return dwBuildNumber;
  290. }
  291.  
  292. //
  293. inline uint TSystem::TVersionInfo::GetPlatformId() const {
  294.   return dwPlatformId;
  295. }
  296.  
  297. //
  298. inline const _TCHAR* TSystem::TVersionInfo::GetVersionStr() const {
  299.   return szCSDVersion;
  300. }
  301.  
  302. #endif  // else/defined(BI_PLAT_WIN16)
  303.  
  304. #endif  // WINSYS_SYSTEM_H
  305.